package com.automannn.casClient;

import org.apache.catalina.Context;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.stereotype.Component;

import java.net.URL;

/**
 * @author chenkh
 * @time 2022/1/18
 */
/*xxx: 内置tomcat，在使用jsp渲染视图时，会出现一些问题，使用本类进行适配*/
@Component
public class TomcatEmbbedJspServletContextCustomizer implements TomcatContextCustomizer {
    @Override
    public void customize(Context context) {
        URL docBaseURL = this.getClass().getClassLoader().getResource("");
        String docBase = docBaseURL.getPath();
        if(docBase.startsWith("/")){
            docBase= docBase.substring(1);
        }
        context.setDocBase(docBase);
    }
}
